package com.tianji.order.controller;


import com.tianji.common.Result;
import com.tianji.common.anno.RepeatSubmit;
import com.tianji.common.utils.SecurityUtil;
import com.tianji.order.pojo.Orders;
import com.tianji.order.service.OrdersService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陈佳
 * @since 2024-10-13
 */
@RestController
@RequestMapping("/orders")
@RequiredArgsConstructor
public class OrdersController {
    private final OrdersService ordersService;

    @PostMapping("/create")
    // 防重复提交
    @RepeatSubmit(limitType = RepeatSubmit.Type.TOKEN, lockTime = 3)
    public Result createOrder(@RequestParam BigDecimal amount) {
        Long userId = SecurityUtil.getUser().getUserId();
        ordersService.createOrder(userId,amount);
        return  Result.success("订单创建成功，订单ID：");
    }

    @ApiOperation(value = "园区企业端app首页数据汇总")
    @GetMapping("/parkDataSummary")
    public Result parkDataSummary() throws ExecutionException, InterruptedException {
        return ordersService.parkDataSummary();
    }
}

